<template>
  <div>
    <div style="text-align: center;width:5rem;padding:0.4rem" id="qrDiv_QrCode">
      <vue-qr :text="text" :margin="0" class="d-block mx-auto" />
      <slot></slot>
    </div>
  </div>
</template>

<script>
import { scrollTo } from "@/utils/scroll-to";
import vueQr from "vue-qr";
// import html2canvas from "html2canvas";

export default {
  name: "SpCode",
  props: {
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 10
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50];
      }
    },
    layout: {
      type: String,
      default: "total, sizes, prev, pager, next, jumper"
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    },
    pagerCount: {
      type: Number,
      default: 7
    },
    text: {
      type: String,
      required: true
    },
    name: {
      type: String,
      required: true
    }
  },
  components: {
    vueQr
  },
  computed: {
    currentPage: {
      get() {
        return this.page;
      },
      set(val) {
        this.$emit("update:page", val);
      }
    },
    pageSize: {
      get() {
        return this.limit;
      },
      set(val) {
        this.$emit("update:limit", val);
      }
    }
  },
  methods: {
    exportQr(text) {
      this.text = "https://goto.huijy.net/" + this.deptId + "/" + trimEqualStr;
      this.exportQrDialog = true;
    },
    handleSizeChange(val) {
      this.$emit("pagination", { page: this.currentPage, limit: val });
      if (this.autoScroll) {
        scrollTo(0, 800);
      }
    },
    handleCurrentChange(val) {
      this.$emit("pagination", { page: val, limit: this.pageSize });
      if (this.autoScroll) {
        scrollTo(0, 800);
      }
    }
  }
};
</script>

<style scoped lang="scss">
#qrDiv_QrCode {
  div {
    width: 100%;
    height: 100%;
    text-align: center;
  }
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
